/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright (C) 2000 Gerwin Klein <lsf@jflex.de>                          *
 * All rights reserved.                                                    *
 *                                                                         *
 * Thanks to Larry Bell and Bob Jamison for suggestions and comments.      *
 *                                                                         *
 * This program is free software; you can redistribute it and/or modify    *
 * it under the terms of the GNU General Public License. See the file      *
 * COPYRIGHT for more information.                                         *
 *                                                                         *
 * This program is distributed in the hope that it will be useful,         *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 * GNU General Public License for more details.                            *
 *                                                                         *
 * You should have received a copy of the GNU General Public License along *
 * with this program; if not, write to the Free Software Foundation, Inc., *
 * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                 *
 *                                                                         *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

package cz.bsa.soft.i18nparser.core;

%%

%byaccj
%class Yylex

%{
  StringBuffer stringBuffer = new StringBuffer();

  private Parser yyparser;

  public Yylex(java.io.Reader r, Parser yyparser) {
    this(r);
    this.yyparser = yyparser;
  }
%}

LineTerminator = \r|\n|\r\n
WhiteSpace = {LineTerminator} | [ \t\f]
Identifier = [a-zA-Z@\.][a-zA-Z1-9@\.]*

%state STRING_QUOTES
%state STRING_DOUBLE_QUOTES

%%
<YYINITIAL>{
    "<" | "</"                  {return Parser.BEGINTAG;}
    ">" | "/>"                  {return Parser.ENDTAG;}
    {WhiteSpace}                { /* ignore */ }
    {Identifier}                {yyparser.yylval = new I18nParserVal(yytext()); return(Parser.IDENTIFIER);}
    \"                          {stringBuffer.setLength(0); yybegin(STRING_DOUBLE_QUOTES);}
    "'"                         {stringBuffer.setLength(0); yybegin(STRING_QUOTES);}
    "(" | ")" | "[" | "]" | "=" | ":"  {return (int) yycharat(0);}
}

<STRING_DOUBLE_QUOTES>{
    \"                      {yybegin(YYINITIAL); yyparser.yylval = new I18nParserVal(stringBuffer.toString()); return(Parser.STRING);}
    [^\n\r\"\\]+            {stringBuffer.append(yytext());}
    \\t                     {stringBuffer.append('\t');}
    \\n                     {stringBuffer.append('\n');}
    \\r                     {stringBuffer.append('\r');}
    \\\"                    {stringBuffer.append('\"');}
    \\                      {stringBuffer.append('\\');}
}

<STRING_QUOTES>{
    "'"                      {yybegin(YYINITIAL); yyparser.yylval = new I18nParserVal(stringBuffer.toString()); return(Parser.STRING);}
    [^\n\r\'\\]+            {stringBuffer.append(yytext());}
    \\t                     {stringBuffer.append('\t');}
    \\n                     {stringBuffer.append('\n');}
    \\r                     {stringBuffer.append('\r');}
    \\'                    {stringBuffer.append("\'");}
    \\                      {stringBuffer.append('\\');}
}

/* error fallback */
[^]    { 
    //System.err.println("Error: unexpected character '"+yytext()+"'"); return 0;
}
